package com.photoeditor.demo.db;


import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;

import java.io.Serializable;

@Entity
public class ExtraBean implements Serializable {

    private static final long serialVersionUID = 1L;

    public final static int RES_TYPE_INSTALLED = 0;
    public final static int RES_TYPE_UNINSTALLED = 1;

    public final static int TYPE_OUTER_NOT_NEED_BUY = 0;
    public final static int TYPE_OUTER_NEED_BUY = 1;
    //内置的
    public final static int TYPE_INTER = 2;

    @Id(autoincrement = true)
    private Long id;

    private String name;
    private String pkgName;

    //0：免费  1：付费 2:内置
    //chargetype 0：免费  1：付费
    //haslock  0：不需要     1：需要
    private int type;

    /**
     * Local排序，上下拖动使用
     */
    private Integer localIndex = 0;

    private boolean isBuy;

    private int version = 1;//版本

    //0 安装的资源
    //1 未安装的资源
    private int resType;

    private String zipPath;

    private Boolean isDownloadOnGP;

    @Generated(hash = 1607026648)
    public ExtraBean(Long id, String name, String pkgName, int type, Integer localIndex, boolean isBuy, int version, int resType, String zipPath, Boolean isDownloadOnGP) {
        this.id = id;
        this.name = name;
        this.pkgName = pkgName;
        this.type = type;
        this.localIndex = localIndex;
        this.isBuy = isBuy;
        this.version = version;
        this.resType = resType;
        this.zipPath = zipPath;
        this.isDownloadOnGP = isDownloadOnGP;
    }

    @Generated(hash = 389459317)
    public ExtraBean() {
    }

    public static ExtraBean create(String name, String pkgName, int type, int localIndex, boolean isbuy, boolean isDownloadOnGP) {
        return create(name, pkgName, type, localIndex, isbuy, 1, RES_TYPE_INSTALLED, null, isDownloadOnGP);
    }

    /**
     * @param name
     * @param pkgName
     * @param type
     * @param isbuy
     * @return
     */
    public static ExtraBean create(String name, String pkgName, int type, int localIndex, boolean isbuy, int version, boolean isDownloadOnGP) {
        return create(name, pkgName, type, localIndex, isbuy, version, RES_TYPE_INSTALLED, null, isDownloadOnGP);
    }

    /**
     * @param name
     * @param pkgName
     * @param type
     * @param isbuy
     * @param version
     * @param resType
     * @return
     */
    public static ExtraBean create(String name, String pkgName, int type, int localIndex, boolean isbuy, int version, int resType, String zipPath, boolean isDownloadOnGP) {
        ExtraBean bean = new ExtraBean();
        bean.setName(name);
        bean.setPkgName(pkgName);
        bean.setType(type);
        bean.setLocalIndex(localIndex);
        bean.setIsBuy(isbuy);
        bean.setVersion(version);
        bean.setResType(resType);
        bean.setZipPath(zipPath);
        bean.setDownloadOnGP(isDownloadOnGP);
        return bean;
    }

    @Override
    public boolean equals(Object o) {
        if (o != null && o instanceof ExtraBean) {
            ExtraBean bean = (ExtraBean) o;
            if (bean.getPkgName().equals(getPkgName()) && bean.getResType() == getResType()) {
                //包名一致且是同一类资源才可以
                return true;
            }
        }
        return false;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPkgName() {
        return this.pkgName;
    }

    public void setPkgName(String pkgName) {
        this.pkgName = pkgName;
    }

    public int getType() {
        return this.type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public boolean getIsBuy() {
        return this.isBuy;
    }

    public void setIsBuy(boolean isBuy) {
        this.isBuy = isBuy;
    }

    public int getVersion() {
        return this.version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public int getResType() {
        return this.resType;
    }

    public void setResType(int resType) {
        this.resType = resType;
    }

    public String getZipPath() {
        return this.zipPath;
    }

    public void setZipPath(String zipPath) {
        this.zipPath = zipPath;
    }

    public boolean isType(int type) {
        return (this.type == type);
    }

    public boolean isResType(int resType) {
        return (this.resType == resType);
    }

    public boolean isDownloadOnGP() {
        return isDownloadOnGP == null ? false:isDownloadOnGP;
    }

    public void setDownloadOnGP(boolean downloadOnGP) {
        isDownloadOnGP = downloadOnGP;
    }

    public Boolean getIsDownloadOnGP() {
        return this.isDownloadOnGP;
    }

    public void setIsDownloadOnGP(Boolean isDownloadOnGP) {
        this.isDownloadOnGP = isDownloadOnGP;
    }

    public int getLocalIndex() {
        if (localIndex == null) {
            localIndex = 0;
        }
        return localIndex;
    }

    public void setLocalIndex(int localIndex) {
        this.localIndex = localIndex;
    }

    public void setLocalIndex(Integer localIndex) {
        this.localIndex = localIndex;
    }
}
